package com.xx.hdfsFx.promptStage;

import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;

public class RenamePrompt {
    public final Button button;
    private final PromptPaneTool promptPaneTool;
    public final TextField textField;
    private final String fileName;
    private final Text text;

    public RenamePrompt(String info, String fileName) {
        this.fileName = fileName;
        promptPaneTool = new PromptPaneTool();
        promptPaneTool.addTitle("重命名");
        promptPaneTool.addInfo(info, "");
        textField = promptPaneTool.addInput("", fileName);
        textField.setPrefSize(500, 30);
        text = promptPaneTool.addErrorInfo("");
        button = promptPaneTool.addButton("重构", "取消");
        button.setDisable(true);
        promptPaneTool.initStage(500, 350);
        initEvent();
    }

    private void initEvent() {
        textField.textProperty().addListener((ob, ov, nv) -> {
            button.setDisable(nv.equals(fileName));
            if (nv.equals("")) {
                text.setText("名称不能为空");
                text.setVisible(true);
                button.setDisable(true);
            } else {
                text.setVisible(false);
            }
//            加入hdfs文件名称关键字判断.
        });
    }

    public void showStage() {
        promptPaneTool.nowStage.show();
    }

    public void closeStage() {
        promptPaneTool.nowStage.close();
    }
}
